package org.example.back.service.user;

import org.example.back.entity.user.UserSleep;
import org.example.back.mapper.user.UserSleepMapper;
import org.example.back.service.advice.UserSleepAdviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Service
public class UserSleepService {

    @Autowired
    private UserSleepMapper userSleepMapper;

    @Autowired
    private UserSleepAdviceService userSleepAdviceService;

    // 插入睡眠记录并清理周月缓存
    public void saveUserSleep(UserSleep userSleep) {
        userSleepMapper.insertUserSleep(userSleep);
        userSleepAdviceService.cleanWeekAndMonthAdviceCache(userSleep.getUserId());
    }

    public UserSleep getUserSleepByDate(Integer userId, LocalDate sleepDate) {
        return userSleepMapper.findUserSleepByDate(userId, sleepDate);
    }

    public List<UserSleep> getUserSleepLastWeek(Integer userId) {
        return userSleepMapper.findUserSleepLastWeek(userId);
    }

    public List<Map<String, Object>> getUserSleepByWeekInMonth(Integer userId) {
        return userSleepMapper.findUserSleepByWeekInMonth(userId);
    }
}
